import com.google.gson.*;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class List2TypeAdapter implements JsonDeserializer<List> {
    @Override
    public List deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {

        if (json.isJsonArray()) {
            List list = new ArrayList();
            System.out.println(typeOfT);
            Type itemType = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
            JsonArray array = json.getAsJsonArray();
            for (int i = 0; i < array.size(); i++) {
                JsonElement jsonElement = array.get(i);
                list.add(context.deserialize(jsonElement, itemType));
            }
            return list;
        } else {
            return Collections.emptyList();
        }

    }
}
